﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Entity;
using BAL;
using Common;
using System.Text;
namespace Web
{
    /// <summary>
    /// Summary description for SynthesizeService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class SynthesizeService : System.Web.Services.WebService
    {

        [WebMethod]
        public string DoViewFeedBack(string sid, string eid,string cid,string flag)
        {
            string DocumentHtml = "";
            try
            {
                if (!PageValidate.IsEmpty(sid) && !PageValidate.IsEmpty(eid) && !PageValidate.IsEmpty(cid))
                {
                    SchoolInfo schoolInfo = School.GetSingleInfo(int.Parse(sid));
                    SubjectInfo subjectInfo = new SubjectInfo();
                    if (schoolInfo != null)
                    {
                        SynthesizeHelper.SchoolId = schoolInfo.Id;
                        SynthesizeHelper.AreaId = schoolInfo.AreaId;
                    }
                    else
                    {
                        return "False";
                    }

                    IList<StudentScoreExtendInfo> listInfos =  StudentScoreExtend.GetList();
                    if (flag.ToLower() == "single")
                    {
                        SynthesizeHelper.ExamRoomId = eid;
                        SynthesizeHelper.AllScoreInfos = listInfos.Where(t => t.ExamRoomId == int.Parse(eid)).ToList();
                        ExamRoomInfo examRoomInfo = ExamRoom.GetSingleInfo(int.Parse(eid));
                        SynthesizeHelper.examPaperInfo = BAL.ExamPaper.GetT1(examRoomInfo.ExamPaperId);
                        subjectInfo = Subject.GetSubjectInfoById(examRoomInfo.SubjectId);
                    }
                    else
                    {
                        string[] arr = eid.Split('-');
                        SynthesizeHelper.ExamRoomIds = arr;
                        SynthesizeHelper.AllScoreInfos = listInfos.Where(t => arr.Contains(t.ExamRoomId.ToString())).ToList();
                        SynthesizeHelper.ExamPaperInfos = new List<ExamPaperInfo>();
                        for (int i = 0; i < arr.Length; i++)
                        {
                            ExamRoomInfo examRoomInfo = ExamRoom.GetSingleInfo(int.Parse(arr[i]));
                            SynthesizeHelper.ExamPaperInfos.Add(BAL.ExamPaper.GetT1(examRoomInfo.ExamPaperId));
                        }
                    }
                    if (!PageValidate.IsEmpty(cid))
                    {
                        switch (cid)
                        {
                            case "0":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "考试科目概况表", SynthesizeHelper.ChartHeader0(), SynthesizeHelper.ChartBody0());
                                break;
                            case "1":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "分组学校名单表", SynthesizeHelper.ChartHeader1(), SynthesizeHelper.ChartBody1());
                                break;
                            case "2":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "成绩统计表", SynthesizeHelper.ChartHeader2(), SynthesizeHelper.ChartBody2());
                                break;
                            case "3":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "各学科总分四线分数统计表", SynthesizeHelper.ChartHeader3(), SynthesizeHelper.ChartBody3());
                                break;
                            case "4":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "上线人数统计表", SynthesizeHelper.ChartHeader4(), SynthesizeHelper.ChartBody4());
                                break;
                            case "5":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "合格率分析表", SynthesizeHelper.ChartHeader5(), SynthesizeHelper.ChartBody5());
                                break;
                            case "6":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "总分成绩分布表", SynthesizeHelper.ChartHeader6(), SynthesizeHelper.ChartBody6());
                                break;
                            case "7":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "各方面水平表", SynthesizeHelper.ChartHeader7(), SynthesizeHelper.ChartBody7());
                                break;
                            case "8":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "各班考试成绩统计表", SynthesizeHelper.ChartHeader8(), SynthesizeHelper.ChartBody8());
                                break;
                            case "9":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "各班级上线比例统计表", SynthesizeHelper.ChartHeader9(), SynthesizeHelper.ChartBody9());
                                break;
                            case "10":
                                DocumentHtml = "TableChart{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "各班级合格率比例统计表", SynthesizeHelper.ChartHeader10(), SynthesizeHelper.ChartBody10());
                                break;
                            case "11":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "不同分组四线比较分析表", SynthesizeHelper.ChartHeader11(), SynthesizeHelper.ChartBody11());
                                break;
                            case "12":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "不同分组合格率比较分析表", SynthesizeHelper.ChartHeader12(), SynthesizeHelper.ChartBody12());
                                break;
                            case "13":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildViewTable(cid, schoolInfo.Name, "优秀生统计表", SynthesizeHelper.ChartHeader13(), SynthesizeHelper.ChartBody13());
                                break;
                            case "14":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildSubjectViewTable(cid, schoolInfo.Name, subjectInfo.Name, "成绩分析表", SynthesizeHelper.ChartHeader14(), SynthesizeHelper.ChartBody14());
                                break;
                            case "15":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildSubjectViewTable(cid, schoolInfo.Name, subjectInfo.Name, "四线成绩分析表", SynthesizeHelper.ChartHeader15(), SynthesizeHelper.ChartBody15());
                                break;
                            case "16":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildSubjectViewTable(cid, schoolInfo.Name, subjectInfo.Name, "成绩分布分析表", SynthesizeHelper.ChartHeader16(), SynthesizeHelper.ChartBody16());
                                break;
                            case "17":
                                DocumentHtml = "Table{$ET:SPLIT}" + BuildSubjectViewTable(cid, schoolInfo.Name, subjectInfo.Name, "合格率分析表", SynthesizeHelper.ChartHeader17(), SynthesizeHelper.ChartBody17());
                                break;
                            default:
                                return "Over";
                        }
                    }
                }
                else
                {
                    return "False";
                }
            }
            catch (Exception ex)
            {
                return "Exception";
            }
            return DocumentHtml;
        }

        private string BuildViewTable(string cid, string schoolName, string tabName, string header, string body)
        {
            StringBuilder sb_table = new StringBuilder();
            string tableTitle = "表" + cid + " 海淀区" + schoolName + tabName;
            sb_table.Append("<h5 class=\"zk_tn\">" + tableTitle + "</h5>");
            sb_table.Append("<table class=\"module_table\">");
            sb_table.Append("<thead>");
            sb_table.Append(header);
            sb_table.Append("</thead>");
            sb_table.Append("<tbody>");
            sb_table.Append(body);
            sb_table.Append("</tbody>");
            sb_table.Append("</table>");
            return sb_table.ToString();
        }
        private string BuildSubjectViewTable(string cid, string schoolName, string subjectName, string tabName, string header, string body)
        {
            StringBuilder sb_table = new StringBuilder();
            string tableTitle = "表" + cid + " 海淀区" + schoolName + subjectName + tabName;
            sb_table.Append("<h5 class=\"zk_tn\">" + tableTitle + "</h5>");
            sb_table.Append("<table class=\"module_table\">");
            sb_table.Append("<thead>");
            sb_table.Append(header);
            sb_table.Append("</thead>");
            sb_table.Append("<tbody>");
            sb_table.Append(body);
            sb_table.Append("</tbody>");
            sb_table.Append("</table>");
            return sb_table.ToString();
        }
        private string BuildPrintTable(string cid, string schoolName, string tabName, string header, string body)
        {
            StringBuilder sb_table = new StringBuilder();
            string tableTitle = "表" + cid + " 海淀区" + schoolName + tabName;
            sb_table.Append("<h5 class=\"zk_tn\">" + tableTitle + "</h5>");
            sb_table.Append("<table class=\"zk_table\">");
            sb_table.Append("<thead>");
            sb_table.Append(header);
            sb_table.Append("</thead>");
            sb_table.Append("<tbody>");
            sb_table.Append(body);
            sb_table.Append("</tbody>");
            sb_table.Append("</table>");
            return sb_table.ToString();
        }
        private string BuildSubjectPrintTable(string cid, string schoolName, string subjectName, string tabName, string header, string body)
        {
            StringBuilder sb_table = new StringBuilder();
            string tableTitle = "表" + cid + " 海淀区" + schoolName + subjectName + tabName;
            sb_table.Append("<h5 class=\"zk_tn\">" + tableTitle + "</h5>");
            sb_table.Append("<table class=\"zk_table\">");
            sb_table.Append("<thead>");
            sb_table.Append(header);
            sb_table.Append("</thead>");
            sb_table.Append("<tbody>");
            sb_table.Append(body);
            sb_table.Append("</tbody>");
            sb_table.Append("</table>");
            return sb_table.ToString();
        }
        private string BuildPrintPart(string html)
        {
            StringBuilder sb_table = new StringBuilder();
            sb_table.Append("<li class=\"zk_part\">");
            sb_table.Append(html);
            sb_table.Append("<li>");
            return sb_table.ToString();
        }
        private string BuildPrintTitle(string title)
        {
            StringBuilder sb_table = new StringBuilder();
            sb_table.Append("<h2 class=\"zk_th3\">");
            sb_table.Append(title);
            sb_table.Append("</h2>");
            return sb_table.ToString();
        }
        private string BuildPrintSubTitle(string title)
        {
            StringBuilder sb_table = new StringBuilder();
            sb_table.Append("<h2 class=\"zk_th2\">");
            sb_table.Append(title);
            sb_table.Append("</h2>");
            return sb_table.ToString();
        }
        private string BuildPrintChart(string memo,string schoolid,string examroomid,string chartid)
        {
            StringBuilder sb_table = new StringBuilder();
            sb_table.Append("<div class=\"zk_chart\">");
            sb_table.Append("<iframe src=\"Synthesize.aspx?SchoolId=" + schoolid + "&ExamRoomIds=" + examroomid + "&ChartId=" + chartid + "\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"320\"></iframe>");
            sb_table.Append("<em class=\"zk_ct\">" + memo + "</em>");
            sb_table.Append("</div>");
            return sb_table.ToString();
        }
        [WebMethod]
        public string DoPrintFeedBack(string sid, string eid, string cid, string flag)
        {
            string DocumentHtml = "";
            try
            {
                if (!PageValidate.IsEmpty(sid) && !PageValidate.IsEmpty(eid) && !PageValidate.IsEmpty(cid))
                {
                    SchoolInfo schoolInfo = School.GetSingleInfo(int.Parse(sid));
                    SubjectInfo subjectInfo = new SubjectInfo();
                    if (schoolInfo != null)
                    {
                        SynthesizeHelper.SchoolId = schoolInfo.Id;
                        SynthesizeHelper.AreaId = schoolInfo.AreaId;
                    }
                    else
                    {
                        return "False";
                    }

                    IList<StudentScoreExtendInfo> listInfos = StudentScoreExtend.GetList();
                    if (flag.ToLower() == "single")
                    {
                        SynthesizeHelper.ExamRoomId = eid;
                        SynthesizeHelper.AllScoreInfos = listInfos.Where(t => t.ExamRoomId == int.Parse(eid)).ToList();
                        ExamRoomInfo examRoomInfo = ExamRoom.GetSingleInfo(int.Parse(eid));
                        SynthesizeHelper.examPaperInfo = BAL.ExamPaper.GetT1(examRoomInfo.ExamPaperId);
                        subjectInfo = Subject.GetSubjectInfoById(examRoomInfo.SubjectId);
                    }
                    else
                    {
                        string[] arr = eid.Split('-');
                        SynthesizeHelper.ExamRoomIds = arr;
                        SynthesizeHelper.AllScoreInfos = listInfos.Where(t => arr.Contains(t.ExamRoomId.ToString())).ToList();
                        SynthesizeHelper.ExamPaperInfos = new List<ExamPaperInfo>();
                        for (int i = 0; i < arr.Length; i++)
                        {
                            ExamRoomInfo examRoomInfo = ExamRoom.GetSingleInfo(int.Parse(arr[i]));
                            SynthesizeHelper.ExamPaperInfos.Add(BAL.ExamPaper.GetT1(examRoomInfo.ExamPaperId));
                        }
                    }
                    if (!PageValidate.IsEmpty(cid))
                    {
                        switch (cid)
                        {
                            case "0":
                                DocumentHtml =BuildPrintPart(BuildPrintTitle("考试科目概况") + BuildPrintTable(cid, schoolInfo.Name, "考试科目概况表", SynthesizeHelper.ChartHeader0(), SynthesizeHelper.ChartBody0()));
                                break;
                            case "1":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("分组学校名单") + BuildPrintTable(cid, schoolInfo.Name, "分组学校名单表", SynthesizeHelper.ChartHeader1(), SynthesizeHelper.ChartBody1()));
                                break;
                            case "2":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("总体成绩统计") + BuildPrintTable(cid, schoolInfo.Name, "成绩统计表", SynthesizeHelper.ChartHeader2(), SynthesizeHelper.ChartBody2()) + BuildPrintChart("成绩比较图", sid, eid, cid));
                                break;
                            case "3":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("上线分数统计") + BuildPrintTable(cid, schoolInfo.Name, "各学科总分四线分数统计表", SynthesizeHelper.ChartHeader3(), SynthesizeHelper.ChartBody3()) + BuildPrintChart("总分四线分数图", sid, eid, cid));
                                break;
                            case "4":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("上线人数统计") + BuildPrintTable(cid, schoolInfo.Name, "上线人数统计表", SynthesizeHelper.ChartHeader4(), SynthesizeHelper.ChartBody4()) + BuildPrintChart("总分上线人数比例图", sid, eid, cid));
                                break;
                            case "5":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("合格率分析") + BuildPrintTable(cid, schoolInfo.Name, "合格率分析表", SynthesizeHelper.ChartHeader5(), SynthesizeHelper.ChartBody5()) + BuildPrintChart("总成绩各水平段比例分析图", sid, eid, cid));
                                break;
                            case "6":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("成绩分布") + BuildPrintTable(cid, schoolInfo.Name, "总分成绩分布表", SynthesizeHelper.ChartHeader6(), SynthesizeHelper.ChartBody6()));
                                break;
                            case "7":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("学业综合竞争力分析") + BuildPrintTable(cid, schoolInfo.Name, "各方面水平表", SynthesizeHelper.ChartHeader7(), SynthesizeHelper.ChartBody7()));
                                break;
                            case "8":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("各班级成绩统计") + BuildPrintTable(cid, schoolInfo.Name, "各班考试成绩统计表", SynthesizeHelper.ChartHeader8(), SynthesizeHelper.ChartBody8()) + BuildPrintChart("各班级总得分率统计图", sid, eid, cid));
                                break;
                            case "9":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("各班级上线人数比例统计") + BuildPrintTable(cid, schoolInfo.Name, "各班级上线比例统计表", SynthesizeHelper.ChartHeader9(), SynthesizeHelper.ChartBody9()) + BuildPrintChart("各班上线比例图", sid, eid, cid));
                                break;
                            case "10":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("各班级合格率分析") + BuildPrintTable(cid, schoolInfo.Name, "各班级合格率比例统计表", SynthesizeHelper.ChartHeader10(), SynthesizeHelper.ChartBody10()) + BuildPrintChart("各班级合格率比例图", sid, eid, cid));
                                break;
                            case "11":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("不同分组学校四线差异") + BuildPrintTable(cid, schoolInfo.Name, "不同分组四线比较分析表", SynthesizeHelper.ChartHeader11(), SynthesizeHelper.ChartBody11()));
                                break;
                            case "12":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("不同分组学校合格率差异") + BuildPrintTable(cid, schoolInfo.Name, "不同分组学校合格率差异", SynthesizeHelper.ChartHeader12(), SynthesizeHelper.ChartBody12()));
                                break;
                            case "13":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle("成绩优秀生统计") + BuildPrintTable(cid, schoolInfo.Name, "优秀生统计表", SynthesizeHelper.ChartHeader13(), SynthesizeHelper.ChartBody13()));
                                break;
                            case "14":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle(subjectInfo.Name + "考试总体成绩分析") + BuildSubjectPrintTable(cid, schoolInfo.Name, subjectInfo.Name, "成绩分析表", SynthesizeHelper.ChartHeader14(), SynthesizeHelper.ChartBody14()));
                                break;
                            case "15":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle(subjectInfo.Name + "考试四线分析报告") + BuildSubjectPrintTable(cid, schoolInfo.Name, subjectInfo.Name, "四线成绩分析表", SynthesizeHelper.ChartHeader15(), SynthesizeHelper.ChartBody15()));
                                break;
                            case "16":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle(subjectInfo.Name + "考试成绩分布") + BuildSubjectPrintTable(cid, schoolInfo.Name, subjectInfo.Name, "成绩分布分析表", SynthesizeHelper.ChartHeader16(), SynthesizeHelper.ChartBody16()));
                                break;
                            case "17":
                                DocumentHtml = BuildPrintPart(BuildPrintTitle(subjectInfo.Name + "考试合格率分析报告") + BuildSubjectPrintTable(cid, schoolInfo.Name, subjectInfo.Name, "合格率分析表", SynthesizeHelper.ChartHeader17(), SynthesizeHelper.ChartBody17()));
                                break;
                            default:
                                return "Over";
                        }
                    }
                }
                else
                {
                    return "False";
                }
            }
            catch (Exception ex)
            {
                return "Exception";
            }
            return DocumentHtml;
        }
    }
}
